<script setup>
import { ref, getCurrentInstance } from "vue";
import { onLoad } from "@dcloudio/uni-app";
const info = ref("123");

const params = ref();
onLoad((options) => {
  // query传参
  // console.log(options, "options");
  // params.value = options;
  // eventChannel传参
  const instance = getCurrentInstance().proxy;
  const eventChannel = instance.getOpenerEventChannel();
  // console.log(eventChannel, "eventChannel");
  eventChannel.emit("toSubassembly", {
    data: "子给父传参了",
  });
  eventChannel.emit("someEvent", { data: "另一个参数" });
  // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
  eventChannel.on("toDetails", function (data) {
    console.log(data);
  });
});

const goBack = () => {
  uni.navigateBack({
    delta: 1, // 回退层数
  });
};
// 获取当前页面栈
// const pages = getCurrentPages();
// console.log(pages, "pages");

const addCache = () => {
  uni.setStorage({
    key: "storage_key",
    data: "hello",
    success: function () {
      console.log("success");
    },
  });
};

const chooseImage = () => {
  uni.chooseImage({
    count: 6, //默认9
    sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
    sourceType: ["album"], //从相册选择
    success: function (res) {
      console.log(JSON.stringify(res.tempFilePaths));
    },
  });
};
</script>

<template>
  <view class="">{{ info }}</view>
  <view class="">传过来的参数是：{{ params?.id }}</view>
  <button @tap="goBack">返回</button>
  <button @tap="addCache">添加缓存</button>
  <button @tap="chooseImage">选择相册</button>
</template>

<style lang="scss" scoped>
//
</style>
